/*
 * led.c
 *
 * Created: 24.01.2012 13:15:50
 *  Author: Luke
 */ 

#include <avr/io.h>
#include <util/delay.h>
#include "led.h"

void ledInit(void)
{
    //make LED_PIN an input (hi-Z)
    LED_DDR &= ~_BV(LED_PIN);
	//turn off internal pull-ups
    LED_PORT &= ~_BV(LED_PIN);	
}

void ledRed(void)
{
	//make LED_PIN an output
    LED_DDR |= _BV(LED_PIN);
	//pull LED_PIN high
    LED_PORT |= _BV(LED_PIN);	
}

void ledBlue(void)
{
	//make LED_PIN an output
    LED_DDR |= _BV(LED_PIN);
	//pull LED_PIN low
    LED_PORT &= ~_BV(LED_PIN);	
}

void ledOff(void)
{
	//make LED_PIN an input (hi-Z)
    LED_DDR &= ~_BV(LED_PIN);
	//turn off internal pull-ups
    LED_PORT &= ~_BV(LED_PIN);		
}

uint8_t ledStatus(void)
{
	if (LED_DDR & _BV(LED_PIN)) 
	    if ((LED_PORT & _BV(LED_PIN)))
            return LED_RED;
		else
		    return LED_BLUE;
	else
	    return LED_OFF;			
}

void ledBlinkBlue(uint8_t number)
{
	for (;number >0;number --)
	{
		ledBlue();
		_delay_ms(50);
		ledOff();
		_delay_ms(50);
	}
}

void ledBlinkRed(uint8_t number)
{
	for (;number >0;number --)
	{
		ledRed();
		_delay_ms(50);
		ledOff();
		_delay_ms(50);
	}
}